package com.smartwebx.ha.dal.realtime.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.smartwebx.ha.dal.config.OracleConfigInfo;
import com.smartwebx.ha.dal.inter.water.IQProcessDataOperatDao;
import com.smartwebx.ha.dal.inter.water.IZProcessDataOperatDao;
import com.smartwebx.ha.dal.realtime.sqlprovider.WasProvider;
import com.smartwebx.ha.dal.usebean.DateValue;
import com.smartwebx.ha.dal.usebean.enu.FlowTypeEnum;

/**
 * 堰闸
 * 
 * @author zhangxi
 * 
 */
public interface WasMapper extends IZProcessDataOperatDao,
		IQProcessDataOperatDao {
	String ST_WAS_R = OracleConfigInfo.REALTIME_NAME + ".ST_WAS_R";

	/**
	 * 单站小时闸上水位过程
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,UPZ val FROM " + ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public List<DateValue> getSingleStatHourZProcess(
			@Param("stcd") String stcd, @Param("startHour") Date startHour,
			@Param("endHour") Date endHour);

	/**
	 * 返回时间点的上一条堰闸闸上水位数据
	 * 
	 * @param stcd
	 * @param datePoint
	 * @return
	 */
	@Select("SELECT UPZ val,TM FROM "
			+ ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM<#{datePoint} AND ROWNUM=1 ORDER BY TM DESC")
	public DateValue getStartHourBeforeZVal(@Param("stcd") String stcd,
			@Param("datePoint") Date datePoint);

	/**
	 * 单站日闸上水位过程 8时
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,UPZ val FROM "
			+ ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startDate} AND TM<#{endDate} AND to_char(TM,'HH24')=8")
	public List<DateValue> getSingleStatDayZProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 单站日总闸流量过程 8时
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,TGTQ val FROM "
			+ ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startDate} AND TM<#{endDate} AND to_char(TM,'HH24')=8")
	public List<DateValue> getSingleStatDayQProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startHour, @Param("endDate") Date endHour);

	/**
	 * 单站小时总闸流量过程
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,TGTQ val FROM " + ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public List<DateValue> getSingleStatHourQProcess(
			@Param("stcd") String stcd, @Param("startHour") Date startHour,
			@Param("endHour") Date endHour);

	/**
	 * 返回时间点的上一条总闸流量数据
	 * 
	 * @param stcd
	 * @param datePoint
	 * @return
	 */
	@Select("SELECT TGTQ val,TM FROM "
			+ ST_WAS_R
			+ " WHERE STCD=#{stcd} AND TM<#{datePoint} AND ROWNUM=1 ORDER BY TM DESC")
	public DateValue getStartHourBeforeQVal(@Param("stcd") String stcd,
			@Param("datePoint") Date datePoint);

	@SelectProvider(type = WasProvider.class,method="getDayFlowerProcessSQL")
	public List<DateValue> getDayFlowerProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate,
			@Param("type") FlowTypeEnum type);

}
